<?php

namespace App\Http\Controllers\PhpCookBook\Arr;

use App\BCAM\CMVariable\CMVariable;
use App\Events\PostSaved;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Event;
class CheckController extends Controller
{
    //4.10 检查一个键是否存在数组中
    public function arrayKeyExists(){
        $array = ['hello'=>null,'world'=>2];
        //完全忽略数组值,只是报告对应一个特定的键是否有相应的数组元素
        $res = array_key_exists('hello',$array);
        if($res){

            //返回bool类型
            //isset判断如果是null会返回false
            CMVariable::compareRes($res,isset($array['hello']));
            return 'yes';
        }
        return 'no';
    }

    //4.11 检查一个元素是否在数组中
    public function inArray(){
        $check = new CheckController();
        Event::fire(new PostSaved($check));
        dd('end');
    }
}
